//
//  ViewController.m
//  UI_13 Practice
//
//  Created by dllo on 16/8/2.
//  Copyright © 2016年 yh. All rights reserved.
//

#import "ViewController.h"
#define kCollection @"reuse"
#define secCollection @"secReuse"
#define firstHead @"firstReuse"
#import "FirstCollectionViewCell.h"
#import "SecCollectionViewCell.h"

@interface ViewController ()<UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) UICollectionView *secCollectionView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.view.backgroundColor = [UIColor whiteColor];
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake(190, 100);
    layout.minimumInteritemSpacing = 10;
    layout.minimumLineSpacing = 10;
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    layout.sectionInset = UIEdgeInsetsMake(15, 10, 10, 10);
    layout.headerReferenceSize = CGSizeMake(0, 50);
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 360) collectionViewLayout:layout];
    self.collectionView.backgroundColor = [UIColor whiteColor];

    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    [self.view addSubview:self.collectionView];
    
    [self.collectionView registerClass:[FirstCollectionViewCell class] forCellWithReuseIdentifier:kCollection];
    
//    [self.collectionView registerClass:[FirstCollectionViewCell class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:firstHead];
    
    self.view.backgroundColor = [UIColor whiteColor];
    UICollectionViewFlowLayout *layout1 = [[UICollectionViewFlowLayout alloc] init];
    layout1.itemSize = CGSizeMake(120, 120);
    layout1.minimumInteritemSpacing = 10;
    layout1.minimumLineSpacing = 10;
    layout1.scrollDirection = UICollectionViewScrollDirectionVertical;
    layout1.sectionInset = UIEdgeInsetsMake(15, 10, 10, 10);
    layout1.headerReferenceSize = CGSizeMake(0, 50);
    
    self.secCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 380, self.view.frame.size.width, 800) collectionViewLayout:layout1];
    self.secCollectionView.backgroundColor = [UIColor whiteColor];
    
    self.secCollectionView.delegate = self;
    self.secCollectionView.dataSource = self;
    [self.view addSubview:self.secCollectionView];
    
    [self.secCollectionView registerClass:[SecCollectionViewCell class] forCellWithReuseIdentifier:secCollection];

    
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    if ([collectionView isEqual:self.collectionView]) {
        return 1;
    } else {
        return 1;
    }
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    if ([collectionView isEqual:self.collectionView]) {
        return 10;
    } else {
        return 107;
    }
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    if ([collectionView isEqual:self.collectionView]) {
        FirstCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCollection forIndexPath:indexPath];
    cell.contentView.backgroundColor = [UIColor yellowColor];
        return cell;
    } else {
        SecCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:secCollection forIndexPath:indexPath];
        cell.contentView.backgroundColor = [UIColor redColor];
        return cell;
    }
}

//- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
//    UICollectionReusableView *reuseView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:firstHead forIndexPath:indexPath];
//    reuseView.backgroundColor = [UIColor greenColor];
//    return reuseView;
//}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
